<!-- 
 * @Author: guanpf 992093924@qq.om
 * @Date: 2023-06-26 16:03:37
 * @LastEditTime: 2023-06-29 17:24:23
 * @LastEditors: guanpf
 * @Description: 
 * @FilePath: /ZCGL_WX/src/views/main/index.vue
 -->
<template>
  <div>
    <SideBar v-if="isLogin" v-show="false"></SideBar>
    <keep-alive>
      <router-view v-if="$route.meta.keepAlive"></router-view>
        <!-- <router-view v-if="$route.meta.keepAlive" class="router-content" :class="$route.path=='/applicationl'?'no-nav':'have-nav'">
        </router-view> -->
    </keep-alive>
    <router-view v-if="!$route.meta.keepAlive"></router-view>
    <div v-show="false" class="ruler" @click="$router.push('/ruler')" alt=""></div>
  </div>
</template>

<script>
import { mapState, mapActions } from 'vuex'
import SideBar from '@/components/common/side-bar'
export default {
  components:{ SideBar },
  data(){
    return{
      fromRoutePath:''
    }
  },
  
  // watch:{
  //     $route(to, from) {
  //         // 对路由变化作出响应...
  //         console.log('indexto',to)
  //         console.log('indexfrom',from)
  //         // if(to.path == '/login'){
  //         //   this.fromRoutePath = from.path
  //         //   this.initRoute()
  //         // }
  //     }
  // },
  created(){
    // this.initRoute() 
  },
  mounted(){
    this.initRoute()
    if(!this.userInfo.token && this.$route.path!='/login'){
      this.$router.push("/login")
    }
  },
  methods:{
      ...mapActions("routes", ["setRouteList"]),
      setStoreRoute(routeList,title){
        document.title = title
        this.setRouteList(routeList)
        // for(let i in routeList){
        //   for(let j in routeList[i].items){
        //     if(routePath == routeList[i].items[j].route){
        //       return
        //     }
        //   }
        // }
      },
      initRoute(){
        if(this.routeList.length==0){
          if(this.$route.path.includes('/leave')){
            this.setStoreRoute(this.glConfig.leaveRoute,'出差请假')
          }
          if(this.$route.path.includes('/message')){
            this.setStoreRoute(this.glConfig.messageRoute,'出差请假')
          }
          if(this.$route.path.includes('/meeting')){
            this.setStoreRoute(this.glConfig.meetingRoute,'出差请假')
          }
        }
      }
  },

  computed: {
      ...mapState({
        userInfo: state=>state.user.userInfo ,
        routeList: (state) => state.routes.routeList,
      }),
      isLogin(){
        if(this.userInfo.token){
          return true
        } else {
          return false
        }
      }
  }
}
</script>

<style lang="less" scoped>
  .ruler{
    position: fixed;
    right: 20px;
    bottom: 20px;
    width: 50px;
    height: 50px;
    background-image: url('../../assets/images/ruler.png');
    z-index: 10000;
    background-size: 100%;
  }
</style>